package com.cgbl.service.assist

import android.text.TextUtils
import api.WorkServiceFactory
import com.robot.base.common.api.AbstractSubscriber
import com.robot.base.common.api.AbstractViewModelSubscriber
import com.robot.base.model.BaseResponse
import com.robot.base.model.TypeBean

object DictTypeAssist {

    private const val TYPE_CAREER = "career_type"

    private val careerList = arrayListOf<TypeBean>()

    fun refreshCareerDictType(refreshSuccess: () -> Unit = {}) {
        WorkServiceFactory.getDictType(TYPE_CAREER)
            .subscribe(object : AbstractSubscriber<BaseResponse<List<TypeBean>>>(null) {
                override fun onNext(t: BaseResponse<List<TypeBean>>) {
                    careerList.clear()
                    careerList.addAll(t.data)
                    refreshSuccess.invoke()
                }
            })
    }

    fun getCareerSource() = careerList

    fun getCareerValue(label: String): String? {
        careerList.forEach {
            if (TextUtils.equals(it.label, label)) {
                return it.value
            }
        }
        return ""
    }
}